﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
//using MySql.Data.MySqlClient;

namespace DatabasePlugin
{
    public static class DbTypeFactory
    {
        public static IDbConnection GetDbConnection(string dbType)
        {
            IDbConnection retVal = null;
            try
            {
                switch (dbType.ToLower())
                {
                    case "access":
                        retVal = new System.Data.OleDb.OleDbConnection();
                        break;

                    case "mssql":
                        retVal = new System.Data.SqlClient.SqlConnection();
                        break;

                    default:
                        retVal = new MySql.Data.MySqlClient.MySqlConnection();
                        break;
                }
            }
            catch
            {
                // in case we try MySQL and it doesn't exist on this machine
                retVal = new System.Data.OleDb.OleDbConnection();
            }

            return retVal;

        }

        public static IDbCommand GetDbCommand(string dbType)
        {
            IDbCommand retVal = null;

            try
            {
                switch (dbType.ToLower())
                {
                    case "access":
                        retVal = new System.Data.OleDb.OleDbCommand();
                        break;

                    case "mssql":
                        retVal = new System.Data.SqlClient.SqlCommand();
                        break;


                    default:
                        retVal = new MySql.Data.MySqlClient.MySqlCommand();
                        break;
                }

            }
            catch
            {
                // in case we try MySQL and it doesn't exist on this machine
                retVal = new System.Data.OleDb.OleDbCommand();
            }

            return retVal;

        }
    }
}
